package org.haptimap.examples;

import org.haptimap.hcimodules.touchovermap.Projection;

import com.google.android.maps.GeoPoint;

import android.graphics.Point;
import android.location.Location;

/*
 * GoogleProjection implements the interface Projection.
 * Use this class in case you are relying on the Android Maps API.
 */
public class GoogleProjection implements Projection {
	private com.google.android.maps.Projection projection;
	
	public GoogleProjection(com.google.android.maps.Projection projection) {
		this.projection = projection;
	}
	
	public Location fromPixels(int x, int y) {
		Location location = new Location("projection");
		
		// Convert GeoPoint to Location
		GeoPoint point = this.projection.fromPixels(x, y);
		
		float latitude = point.getLatitudeE6() / 1E6F;
		float longitude = point.getLongitudeE6() / 1E6F;

		location.setLatitude(latitude);
		location.setLongitude(longitude);
		
		return location;
	}

	public Point toPixels(Location in, Point out) {
		// Convert Location to GeoPoint
		GeoPoint geo_in = new GeoPoint((int) (in.getLatitude()*1E6), (int) (in.getLongitude()*1E6));
		return this.projection.toPixels(geo_in, out);
	}

}
